package com.soboot.base.util;

import com.fasterxml.jackson.databind.ObjectMapper;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author:
 * @createTime: 2022年09月20日 13:01:28
 * @version:
 * @Description:
 * @Copyright:
 */
public class ResponseUtil {

    /**
     * 设置响应
     *
     * @param response    HttpServletResponse
     * @param contentType content-type
     * @param status      http状态码
     * @param value       响应内容
     * @throws IOException IOException
     */
    public static void writeResponse(String contentType, int status,
                                     Object value,HttpServletResponse response) throws IOException {
        response.setContentType(contentType);
        response.setStatus(status);
        ObjectMapper objectMapper = new ObjectMapper();
        response.getOutputStream().write(objectMapper.writeValueAsBytes(value));
    }
}
